package com.ruoyi.erecord.employee.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erecord.employee.domain.bo.EmployeeImportAttachBo;
import com.ruoyi.erecord.employee.domain.bo.EmployeeImportBaseBo;
import com.ruoyi.erecord.employee.domain.bo.EmployeeImportBo;
import com.ruoyi.erecord.employee.domain.vo.EmployeeImportAttachVo;
import com.ruoyi.erecord.employee.service.IEmployeeImportAttachService;
import com.ruoyi.erecord.employee.service.impl.EmployeeImportExcelService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员导入附件
 *
 * @author cc
 * @date 2023-04-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erecord/employeeImportAttach")
public class EmployeeImportAttachController extends BaseController {

    private final IEmployeeImportAttachService iEmployeeImportAttachService;
    private final EmployeeImportExcelService employeeImportExcelService;
    /**
     * 查询人员导入附件列表
     */
    @SaCheckPermission("erecord:employeeImportAttach:list")
    @GetMapping("/list")
    public TableDataInfo<EmployeeImportAttachVo> list(EmployeeImportAttachBo bo, PageQuery pageQuery) {
        return iEmployeeImportAttachService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出人员导入附件列表
     */
    @SaCheckPermission("erecord:employeeImportAttach:export")
    @Log(title = "人员导入附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EmployeeImportAttachBo bo, HttpServletResponse response) {
        List<EmployeeImportAttachVo> list = iEmployeeImportAttachService.queryList(bo);
        ExcelUtil.exportExcel(list, "人员导入附件", EmployeeImportAttachVo.class, response);
    }

    /**
     * 获取人员导入附件详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("erecord:employeeImportAttach:query")
    @GetMapping("/{id}")
    public R<EmployeeImportAttachVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iEmployeeImportAttachService.queryById(id));
    }

    /**
     * 新增人员导入附件
     */
    @SaCheckPermission("erecord:employeeImportAttach:add")
    @Log(title = "人员导入附件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EmployeeImportAttachBo bo) {
        return toAjax(iEmployeeImportAttachService.insertByBo(bo));
    }

    /**
     * 修改人员导入附件
     */
    @SaCheckPermission("erecord:employeeImportAttach:edit")
    @Log(title = "人员导入附件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EmployeeImportAttachBo bo) {
        return toAjax(iEmployeeImportAttachService.updateByBo(bo));
    }

    /**
     * 删除人员导入附件
     *
     * @param ids 主键串
     */
    @SaCheckPermission("erecord:employeeImportAttach:remove")
    @Log(title = "人员导入附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iEmployeeImportAttachService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
    
    @SaCheckPermission("erecord:employeeImportAttach:import")
    @Log(title = "人员导入主", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping("/importAttach")
    public R<Void> importAttach(@Validated(AddGroup.class) @RequestBody EmployeeImportBo bo) {
        return toAjax(this.employeeImportExcelService.importZip(bo));
    }
}
